<?
define('BASEPATH', true);
include('../inc/config.php');
if(!$is_online){exit;}

$id = $db->EscapeString($_GET['id']);

if(isset($_GET['id'])){
	if($_GET['step'] == "skip"){
		$db->Query("INSERT INTO `dugg` (user_id, site_id) VALUES('".$data['id']."', '".$id."')");
		echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Done!</b></font></td></tr></table>';
	}else{
		$data3 = $db->FetchArray($db->Query("SELECT id,t_name FROM `digg` WHERE `user`='".$data['id']."'"));
		$site = $db->FetchArray($db->Query("SELECT id,t_name,cpc FROM `digg` WHERE `id`='".$id."'"));
		$key = rand(10000,20000);
		$url  = "http://services.digg.com/1.0/endpoint?method=fan.getAll&username=".$site['t_name']."&count=".$key;
		$page = get_data($url);
		$plused = $db->GetNumRows($db->Query("SELECT * FROM `dugg` WHERE `site_id`='".$id."' AND `user_id`='".$data['id']."'"));

		$x = $data3['t_name'];
		if ($page == FALSE) { 
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Error!</b></font></td></tr><tr><td><center><b>We can\'t verify followers!</b></center></td></tr></table>';
		}elseif($plused > 0){
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Error!</b></font></td></tr><tr><td><center><b>You already followed @'.$site['t_name'].'!</b></center></td></tr></table>';
		}elseif (preg_match("/$x/i", $page)) {
			$db->Query("UPDATE `users` SET `coins`=`coins`+'".$site['cpc']."' WHERE `id`='".$data['id']."'");
			$db->Query("UPDATE `digg` SET `visits`=`visits`+'1', `points`=`points`-'".$site['cpc']."' WHERE `id`='".$id."'");
			$db->Query("INSERT INTO `dugg` (user_id, site_id) VALUES('".$data['id']."', '".$id."')");
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Success!</b></font></td></tr><tr><td><center><b>You followed @'.$site['t_name'].'!<br><font color=\"#d4a1ff\" size=\"3\">You got '.$site['cpc'].' Coin!</font></center></td></tr></table>';
		}else{
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td><center><b>Digg says you aren\'t following '.$z.'!</b><br><i>Check again if you are logged into ' . $data3['t_name']. ' on Digg.</i><br><b>Try Confirming again or Skip them!</b></center></td></tr></table><br>';
		}
	}
}
?>